package org.destiny;

import java.util.List;

import javax.validation.Valid;

import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.validation.FieldError;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class TestController {

    @RequestMapping("/index")
    public String index() {
        return "index";
    }

    @RequestMapping("/validator")
    @ResponseBody
    public String testValidator(@Valid StudentDTO student, BindingResult result) {

        String strResult = "";
        List<FieldError> fieldErrors = result.getFieldErrors();
        if (null != fieldErrors) {
            for (FieldError fieldError : fieldErrors) {
                strResult = strResult + "-" + fieldError.getField() + "-" + fieldError.getDefaultMessage();
            }
        }
        return strResult;
    }

}
